﻿using System.Web;
using UI.Models.ShoppingCart;

namespace UI.Infrastructure.ShoppingCart
{
    public class CartRepository : ICartRepository
    {
        private const string CartKey = "CART_KEY";

        private Cart Cart
        {
            get
            {
                var cart = HttpContext.Current.Session[CartKey] as Cart;
                if (cart == null)
                {
                    cart = new Cart();
                    HttpContext.Current.Session[CartKey] = cart;
                }
                return cart;
            }
        }

        #region ICartRepository Members

        public Cart GetCart()
        {
            return Cart;
        }

        #endregion
    }
}